package com.senney.practice.jedis;

import redis.clients.jedis.Jedis;

import java.util.*;

public class TestJedisAPI {
    public static void main(String[] args) {
        Jedis jedis = new Jedis("192.168.2.101",6379);
        // key
        Set<String> sets = jedis.keys("*");
        sets.stream().forEach(System.out::println);
        System.out.println("jedis.exists===>"+jedis.exists("k2"));
        System.out.println(jedis.ttl("k1"));

        // string
        System.out.println(jedis.get("k3"));
        jedis.set("k4","v4_redis");
        System.out.println("---------------------------------------");
        jedis.mset("str1","v1","str2","v2","str3","v3");
        System.out.println(jedis.mget("str1","str2","str3"));

        // list
        System.out.println("---------------------------------------");
        jedis.lpush("mylist","v1","v2","v3","v4","v5");
        List<String> list = jedis.lrange("mylist",0,-1);
        list.stream().forEach(System.out::println);

        // set
        jedis.sadd("orders","jd001");
        jedis.sadd("orders","jd002");
        jedis.sadd("orders","jd003");
        Set<String> orders=jedis.smembers("orders");
        for(Iterator iterator=orders.iterator();iterator.hasNext();){
            String s = (String) iterator.next();
            System.out.println(s);
        }
        jedis.srem("orders","jd002");
        System.out.println(jedis.smembers("orders").size());

        // hash
        jedis.hset("hash01","userName","lisi");
        System.out.println(jedis.hget("hash01","userName"));
        Map<String,String> map = new HashMap<>();
        map.put("telphone","12345678901");
        map.put("address","adhbs");
        map.put("email","abdc@163.com");
        jedis.hmset("hash02",map);
        List<String> result=jedis.hmget("hash02","telphone","email");
        result.stream().forEach(System.out::println);

        // zset
        jedis.zadd("zset01",60d,"v1");
        jedis.zadd("zset01",60d,"v2");
        jedis.zadd("zset01",60d,"v3");
        jedis.zadd("zset01",60d,"v4");
        Set<String> s1=jedis.zrange("zset01",0,-1);
        for(Iterator<String> iterator=s1.iterator();iterator.hasNext();){
            System.out.println(iterator.next());
        }


    }
}
